#pragma once
#include <Rz/Object.h>
#include <Rz/Graphics/Render/IRenderDevice.h>
#include <Rz/Graphics/Render/Libraries/OpenGL/GL.h>
#include <Rz/Graphics/Render/Libraries/OpenGL/GLRenderTarget2D.h>

namespace Rz { namespace Graphics { namespace Render { namespace Libraries { namespace OpenGL {

class GLRenderDevice :
	public Object,
	public IRenderDevice
{
	public:
		RZ_RTTI(Rz::Graphics::Render::Libraries::OpenGL, GLRenderDevice);
		RZ_RTTI_IMPLEMENTS(Object, IRenderDevice);
		RZ_RTTI_END;

		bool Init();
		void End();

		virtual void Clear(ClearOptions clearMode, const Math::Vector4& color) override;

		virtual IRenderTarget2D* CreateRenderTarget2D(const Math::Size& size) override;
		virtual IRenderTarget2D* CreateRenderTarget2D(const Math::Size& size, SurfaceFormat surfaceFormat) override;
		virtual IRenderTarget2D* CreateRenderTarget2D(const Math::Size& size, SurfaceFormat surfaceFormat, DepthFormat depthFormat) override;
		virtual IRenderTarget2D* CreateRenderTarget2D(const Math::Size& size, SurfaceFormat surfaceFormat, DepthFormat depthFormat, RenderTargetUsage usage) override;

		virtual IVertexBuffer* CreateVertexBuffer() override;
		virtual IIndexBuffer* CreateIndexBuffer() override;
		virtual IVertexArray* CreateVertexArray() override;
		virtual IEffect* CreateEffect() override;
		virtual IEffect* CreateEffect(const String& shader) override;

		virtual Geometry* CreateGeometry() override;

		virtual Viewport* CreateViewport(const Math::Rectangle& bounds) override;

		virtual void DrawIndexedPrimitives(PrimitiveType primitiveType, IVertexArray* vertexArray) override;

		virtual GBuffer* CreateGBuffer(const Math::Size& size) override;

		virtual void SetRenderTarget(IRenderTarget2D* renderTarget) override;
		virtual void SetRenderTargets(std::initializer_list<IRenderTarget2D*> renderTargets) override;

	private:
		void SetNativeFramebuffer();
};

} } } } }
